package co.yixiang.modules.user.service.mapper;

import co.yixiang.common.mapper.CoreMapper;
import co.yixiang.modules.user.domain.MonthlyManagementAward;
import co.yixiang.modules.user.domain.MonthlyManagementAwardDetail;
import co.yixiang.modules.user.vo.MonthlyAwardDetailVo;
import co.yixiang.modules.user.vo.MonthlyAwardVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;

/**
* @author lsh
* @date 2021-05-12
*/
@Repository
public interface MonthlyManagementAwardDetailMapper extends CoreMapper<MonthlyManagementAwardDetail> {

    @Select(" SELECT * " +
            " FROM monthly_management_award_detail  " +
            " where (uid=#{uid} or parent_id =#{uid}) and month=#{month} and is_open =1 and status =1 " +
            "order by create_time desc  ")
    List<MonthlyManagementAwardDetail> getManagementAward4monthList(Page page, @Param("uid") Long uid, @Param("month") String month);

    @Select(" SELECT t.uid,t.level,sum(t.total_sum) as total_sum " +
            " FROM monthly_management_award_detail t " +
            " where t.month=#{month} group by t.uid,t.level" +
            " order by t.create_time desc  ")
    List<HashMap<String,Object>> getMonthData(@Param("month") String month);

    @Select(" SELECT uid,month,SUM(total_sum) AS total_sum " +
            " FROM monthly_management_award_detail  " +
            " where uid =#{uid} and month=#{month} " +
            " GROUP BY uid,month "+
            " order by create_time desc  ")
    MonthlyAwardVo getAwardMain4monthList(Page page, @Param("uid") Long uid, @Param("month") String month);

    @Select(" SELECT uid,month,SUM(total_sum) AS total_sum " +
            " FROM monthly_management_award_detail  " +
            " where parent_id =#{uid} and month=#{month} " +
            " GROUP BY uid,month "+
            " order by create_time desc  ")
    List<MonthlyAwardDetailVo> getAwardBranch4monthList(Page page, @Param("uid") Long uid, @Param("month") String month);
}
